from django.db import models

from lapi_app.models.user_model.user_info import Userinfo


class Project(models.Model):
    """
    项目
    """
    project_name = models.CharField("项目名称", max_length=200, null=False)
    project_describe = models.TextField("项目描述", default="", null=True)
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    update_time = models.DateTimeField("更新时间", auto_now_add=True)
    user = models.ForeignKey(Userinfo, on_delete=models.CASCADE, default=1)

    def __str__(self):
        return self.project_name


class Bug_menu(models.Model):
    id = models.AutoField(primary_key=True)
    label = models.CharField(max_length=38, verbose_name='菜单名称')
    pid = models.IntegerField(default=0, verbose_name='父id')
    type = models.IntegerField(default=1, verbose_name='类型', null=False)
    project = models.ForeignKey(Project, on_delete=models.CASCADE, default=1)
    # 1是项目目录，2是需求文档
    project_prd = models.CharField(max_length=255, verbose_name='需求文档地址', null=True)
    m_user = models.ForeignKey(Userinfo, on_delete=models.CASCADE)
    create_time = models.DateTimeField("创建时间", auto_now_add=True, null=True)
    update_time = models.DateTimeField("编辑时间", auto_now_add=True, null=True)

    def __str__(self):
        return self.id


class Bug(models.Model):
    """
    缺陷管理
    """
    bug_name = models.CharField("bug名称", max_length=200, null=False)
    bug_urgency = models.IntegerField("紧急程度", null=False, default=3)  # 1：紧急，2：高，3：一般，5：无关紧要
    bug_severity = models.IntegerField("严重程度", null=False, default=3)  # 1：致命，2：严重，3：一般，5：建议，5：提示
    bug_status = models.IntegerField("处理状态", null=False, default=3)  # 1：新，2：接受，3：已解决，5：拒绝，5：重新打开，6：已关闭，7：挂起
    bug_content = models.TextField("bug描述", default="", null=True)
    bug_menu = models.ForeignKey(Bug_menu, on_delete=models.CASCADE, default=1)
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    update_time = models.DateTimeField("处理时间", auto_now_add=True)
    user = models.ForeignKey(Userinfo, on_delete=models.CASCADE)  # 创建人
    deal_user = models.IntegerField("处理人", null=False, default=1)
    updater_user = models.IntegerField("更新人", null=False, default=1)

    def __str__(self):
        return self.bug_name


class Bug_history(models.Model):
    """
    缺陷流转历史记录
    """
    deal_content = models.TextField("处理方法描述", default="", null=True)
    deal_user = models.ForeignKey(Userinfo, on_delete=models.CASCADE)  # 处理人
    bug = models.ForeignKey(Bug, on_delete=models.CASCADE, null=True)
    create_time = models.DateTimeField("创建时间", auto_now_add=True)

    def __str__(self):
        return self.deal_content


class Bug_img(models.Model):
    """
    bug图片上传保存
    """
    img_address = models.FileField(upload_to='media/', verbose_name='路径')
    bug = models.ForeignKey(Bug, on_delete=models.CASCADE, verbose_name='bug_id')

    def __str__(self):
        return self.img_address
